<?php
// +----------------------------------------------------------------------
// | Author: 发仔 <i@fazi.me> 
// +----------------------------------------------------------------------

namespace app\admin\controller;

use think\Db;

class role extends Base
{
	protected $id = 'role_id';
	protected $table = 'role';
	protected $join = ['area a','a.area_id = m.area_id','left'];
	
	protected function options( $item = [] ) {
		
		$ztree = Db::name('menu')->field('id,name,pid AS pId')->select();
		$ztree[0]['open'] = true;
		
		$item['menus'] = explode(',',$item['menus']);
		foreach($ztree AS $id => $z) {
			if(in_array($z['id'],$item['menus'])) {
				$ztree[$id]['checked'] = true;
			}
		}
		$this->assign('zTree',json_encode($ztree));
		
		//
		$areas = Db::name('area')->whereNull('delete_time')->column('*','area_id');
//		$area_ids = Arr2Sibling($areas,0,0,'area_id','area_pid');
		$area_ids = $areas;
		$this->assign('area_ids', TplOptions($area_ids, $item['area_id'],'area_name', 'area_id') );
		
		
		return $item;
		
	}
	
	
	public function users() {
		
		$id = input('param.role_id');
		$list = Db::name('user')->select();
		$this->assign('list',$list);
		
		return $this->out();
		
	}
    
}
